/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-05-06
 * Time: 14:59
 */


class Solution1 {
    public int longestBeautifulSubstring(String word) {
// 如果right - right-1<0就证明元音字母没有按照升序排列，并且right之前不能构成完美字符串，我们就从right开始继续找(left=right)所以type置成1重新开始，相反>0证明是升序，type++，也就是出现了几种不同的字母，如果type=5那就证明找到了完美字符串更新字符串长度，如果等于0证明是重复的那就声明也不做
        if(word.length()<5){
            return 0;
        }
        int ans =0;
        int type =0;
        int left =0;
        int right =1;
        int len = word.length();
        while(right<len){
            char[] chars = word.toCharArray();
            int tmp = chars[right]-chars[right-1];
            if(tmp>0){
                type++;
            }
            if(tmp<0){
                left = right;//从头开始
                type=1;
            }
            if(type==5){
                ans = Math.max(ans,right-left+1);
            }
            right++;
        }
        return ans;
    }
}

class Solution {
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
// 老板不生气的时候，顾客的满意度是固定的，而生气的满意度就影响最后的结果，就转化成求最大k改变的满意度，我们先将老板没有生气的顾客数量加起来，再将这些生气的全部置为0，我们就寻找最大的minutes的最大子数组就可以了
        //1.先将所以老板不生气的总数量加起来
        int total =0;
        for(int i =0;i<customers.length;++i){
            if(grumpy[i]!=1){
                total+=customers[i];
                customers[i] = 0;
            }
        }
        //创建滑动窗口寻找最大的minutes的最大子数组
        int left =0;
        int right = 0;
        int len = customers.length;
        int cnt = 0;
        while(right<len){
            int tmp =minutes;
            int sum =0;
            while(right<len&&tmp!=0){
                sum+=customers[right++];
                tmp--;
            }
            cnt = Math.max(cnt,sum);
            ++left;
            right = left;
        }
        return total+cnt;
    }
}
class Solution4 {
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
// 老板不生气的时候，顾客的满意度是固定的，而生气的满意度就影响最后的结果，就转化成求最大k改变的满意度，我们先将老板没有生气的顾客数量加起来，再将这些生气的全部置为0，我们就寻找最大的minutes的最大子数组就可以了
        //1.先将所以老板不生气的总数量加起来
        int total =0;
        for(int i =0;i<customers.length;++i){
            if(grumpy[i]==0){
                total+=customers[i];
                customers[i] = 0;
            }
        }
        //找最大的minutes子数组
        int max =0;
        int sum =0;
        for(int i =0;i<customers.length;++i){
            sum+=customers[i];
            if(i>=minutes){
                sum-=customers[i-minutes];
            }
            max = Math.max(max,sum);
        }
        return total+max;

    }
}
public class TestDemo {

    public static void main(String[] args) {
        Solution solution = new Solution();
       /// customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
        int[] customers = {1,0,1,2,1,1,7,5};
        //1+1+1+7
        //0 0 0 0 -》0 0 0 2 0 1 0 5
        int[] grumpy = {0,1,0,1,0,1,0,1};
        int minutes = 3;
        System.out.println(solution.maxSatisfied(customers, grumpy, minutes));
    }


    public static void main1(String[] args) {
        StringBuilder sb = new StringBuilder();
        String s = "abc";

        for(int i =1;i<s.length();++i){
            if(s.charAt(i-1)<s.charAt(i)){
                System.out.println(1);
            }
        }
    }

}
